home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / MSG Demo 1.4 / source / Fades ƒ / Hilbert fade.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  3.7 KB  |  133 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        Hilbert wipe fade.c
  4.  
  5. Purpose:    Graphic effect to fade main window to solid pattern.
  6.             See comments below for more description.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "timing.h"
  26.  
  27. /* This fills the screen by a Hilbert space-filling curve, which is defined by
  28.    two mutually recursive drawing functions:
  29.    
  30.    X = left, Y, draw, right, X, draw, X, right, draw, Y, left
  31.    Y = right, X, draw, left, Y, draw, Y, left, draw, X, right
  32.    
  33.    Start by drawing X at the highest recursion level from the bottomleft of the
  34.    screen. (At recursion level 1, X and Y are null functions.)
  35. */
  36.  
  37. #define    RecursionLevel    4
  38. #define CorrectTime 1
  39. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  40. #define theWindowWidth (boundsRect.right-boundsRect.left)
  41.  
  42. pascal void HilbertFadeRecurse(Rect boundsRect, Pattern *thePattern,
  43.     int level, int whichpattern, int* x, int* y);
  44. pascal short HilbertFade(Rect boundsRect, Pattern *thePattern);
  45.  
  46. typedef char    Hilby[11];
  47.  
  48. static Hilby    HilbertPattern[]=
  49. {
  50.     {
  51.         0x02,0x69,0x00,0x01,0x42,0x00,0x42,0x01,0x00,0x69,0x02
  52.     },
  53.     {
  54.         0x01,0x42,0x00,0x02,0x69,0x00,0x69,0x02,0x00,0x42,0x01
  55.     }
  56. };
  57.  
  58. static int            HilbertDirection;
  59. static int            vBlockSize;
  60. static int            hBlockSize;
  61.  
  62. pascal void HilbertFadeRecurse(Rect boundsRect, Pattern *thePattern,
  63.     int level, int whichpattern, int* x, int* y)
  64. {
  65.     int                i;
  66.     Rect            source;
  67.     
  68.     for (i=0; i<11; i++)
  69.     {
  70.         switch (HilbertPattern[whichpattern][i])
  71.         {
  72.             case 0x01:     /* turn left */
  73.                 HilbertDirection--;
  74.                 if (HilbertDirection<0) HilbertDirection=3;
  75.                 break;
  76.             case 0x02:     /* turn right */
  77.                 HilbertDirection++;
  78.                 if (HilbertDirection==4) HilbertDirection=0;
  79.                 break;
  80.             case 0x00:    /* draw */
  81.                 StartTiming();
  82.                 SetRect(&source, *x, *y-vBlockSize, *x+hBlockSize, *y);
  83.                 OffsetRect(&source, boundsRect.left, boundsRect.top);
  84.                 SectRect(&source, &boundsRect, &source);
  85.                 FillRect(&source, *thePattern);
  86.                 switch (HilbertDirection)
  87.                 {
  88.                     case 0:
  89.                         *x+=hBlockSize;
  90.                         break;
  91.                     case 1:
  92.                         *y-=vBlockSize;
  93.                         break;
  94.                     case 2:
  95.                         *x-=hBlockSize;
  96.                         break;
  97.                     case 3:
  98.                         *y+=vBlockSize;
  99.                         break;
  100.                 }
  101.                 TimeCorrection(CorrectTime);
  102.                 break;
  103.             case 0x42:    /* call X */
  104.                 if (level>1)
  105.                     HilbertFadeRecurse(boundsRect,thePattern,level-1,0,x,y);
  106.                 break;
  107.             case 0x69:    /* call Y */
  108.                 if (level>1)
  109.                     HilbertFadeRecurse(boundsRect,thePattern,level-1,1,x,y);
  110.                 break;
  111.         }
  112.     }
  113. }
  114.  
  115. pascal short HilbertFade(Rect boundsRect, Pattern *thePattern)
  116. {
  117.     int            curx, cury;
  118.     int            answer, i;
  119.     
  120.     answer=1;
  121.     for (i=0; i<RecursionLevel; i++)
  122.         answer*=2;
  123.     vBlockSize=1+theWindowHeight/answer;    /* used to be 20 */
  124.     hBlockSize=1+theWindowWidth/answer;        /* used to be 32 */
  125.     HilbertDirection=0;
  126.     cury=theWindowHeight;
  127.     curx=0;
  128.     HilbertFadeRecurse(boundsRect,thePattern,RecursionLevel,0,&curx,&cury);
  129.     FillRect(&boundsRect, *thePattern);        /* in case we missed any bits */
  130.     
  131.     return 0;
  132. }
  133.